package com.swsc.xapp.model;

import android.text.TextUtils;

import com.swsc.xapp.offline.lhttpd.ApiException;

import java.time.LocalDateTime;

/**
 * @Author chencl
 * @Date 2021/5/7 23:45
 * @Version 1.0
 * @Description
 */

public class DefectAddReqVO  {

    private Integer id;
    private Integer tenantNo;
    private Integer organNo;
    private Long operatorNo;
    private String operatorName;
    private String operatorType;

   private String batchNo;

    private Long defectNo;
    private String defectCode;

    private Integer stationNo;
    /**
     * 电站
     */

    private String stationName;
    private String organName;

    private String zone;
    /**
     * 巡检时间
     */
    private String patrolTime;

    /**
     * 故障类型
     */
    private Integer faultNo;

    private String faultName;
    /**
     * 故障类型
     */

    private String deviceCode;


    private String deviceName;
    /**
     * 经度
     */

    private Double longitude;
    /**
     * 纬度
     */
    private Double latitude;

    private String model;
    /**
     * 故障损耗
     */
    private Float loss;

    private String state;

    private String faultImg;

    private String faultReason;

    private String remark;

    private LocalDateTime dealTime;

    private String faultLevel;

    public Integer getOrganNo() {
        return null == getOrganNo() ? stationNo : getOrganNo();
    }

    public String getOrganName() {
        return (null == organName || "".equals(organName.trim())) ? stationName : organName;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getTenantNo() {
        return tenantNo;
    }

    public void setTenantNo(Integer tenantNo) {
        this.tenantNo = tenantNo;
    }

    public void setOrganNo(Integer organNo) {
        this.organNo = organNo;
    }

    public Long getOperatorNo() {
        return operatorNo;
    }

    public void setOperatorNo(Long operatorNo) {
        this.operatorNo = operatorNo;
    }

    public String getOperatorName() {
        return operatorName;
    }

    public void setOperatorName(String operatorName) {
        this.operatorName = operatorName;
    }

    public String getOperatorType() {
        return operatorType;
    }

    public void setOperatorType(String operatorType) {
        this.operatorType = operatorType;
    }

    public String getBatchNo() {
        return batchNo;
    }

    public void setBatchNo(String batchNo) {
        this.batchNo = batchNo;
    }

    public Long getDefectNo() {
        return defectNo;
    }

    public void setDefectNo(Long defectNo) {
        this.defectNo = defectNo;
    }

    public String getDefectCode() {
        return defectCode;
    }

    public void setDefectCode(String defectCode) {
        this.defectCode = defectCode;
    }

    public Integer getStationNo() {
        return stationNo;
    }

    public void setStationNo(Integer stationNo) {
        this.stationNo = stationNo;
    }

    public String getStationName() {
        return stationName;
    }

    public void setStationName(String stationName) {
        this.stationName = stationName;
    }

    public void setOrganName(String organName) {
        this.organName = organName;
    }

    public String getZone() {
        return zone;
    }

    public void setZone(String zone) {
        this.zone = zone;
    }

    public String getPatrolTime() {
        return patrolTime;
    }

    public void setPatrolTime(String patrolTime) {
        this.patrolTime = patrolTime;
    }

    public Integer getFaultNo() {
        return faultNo;
    }

    public void setFaultNo(Integer faultNo) {
        this.faultNo = faultNo;
    }

    public String getFaultName() {
        return faultName;
    }

    public void setFaultName(String faultName) {
        this.faultName = faultName;
    }

    public String getDeviceCode() {
        return deviceCode;
    }

    public void setDeviceCode(String deviceCode) {
        this.deviceCode = deviceCode;
    }

    public String getDeviceName() {
        return deviceName;
    }

    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public Float getLoss() {
        return loss;
    }

    public void setLoss(Float loss) {
        this.loss = loss;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getFaultImg() {
        return faultImg;
    }

    public void setFaultImg(String faultImg) {
        this.faultImg = faultImg;
    }

    public String getFaultReason() {
        return faultReason;
    }

    public void setFaultReason(String faultReason) {
        this.faultReason = faultReason;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public LocalDateTime getDealTime() {
        return dealTime;
    }

    public void setDealTime(LocalDateTime dealTime) {
        this.dealTime = dealTime;
    }

    public String getFaultLevel() {
        return faultLevel;
    }

    public void setFaultLevel(String faultLevel) {
        this.faultLevel = faultLevel;
    }

    public void validSingle(String prefix) {
        this.setId(null);
        if (TextUtils.isEmpty(prefix)) {
            prefix = "[" + this.getDefectCode() + ", " + this.getDeviceName() + "]";
        }

//        BizAssert.isFalse(StringUtils.isBlank(this.getBatchNo()), prefix + "批次号为空");
//        BizAssert.isFalse(StringUtils.isBlank(this.getDefectCode()), prefix + "故障编号为空");
//        BizAssert.isFalse(StringUtils.isBlank(this.getStationName()) || StringUtils.isBlank(this.getOrganName()), prefix + "电站名称为空");
        ApiException.isFalse(null == (this.getStationNo()) && null == this.getOrganNo(), prefix + "电站编号为空");

        ApiException.isFalse(null == (this.getPatrolTime()), prefix + "巡检时间为空");
        ApiException.isFalse(TextUtils.isEmpty(this.getFaultName()), prefix + "故障名称为空");
        ApiException.isFalse(null == (this.getLatitude()), prefix + "经度为空");
        ApiException.isFalse(null == (this.getLatitude()), prefix + "纬度为空");
        ApiException.isFalse(TextUtils.isEmpty(this.getFaultImg()), prefix + "故障图片为空");

        if (null == this.getOrganNo() && null != this.getStationNo()) {
            this.setOrganNo(this.getStationNo());
        }
        if (null != this.getOrganNo() && null == this.getStationNo()) {
            this.setStationNo(this.getOrganNo());
        }
        if (TextUtils.isEmpty(this.getOrganName()) && !TextUtils.isEmpty(this.getStationName())) {
            this.setOrganName(this.getStationName());
        }
        if (!TextUtils.isEmpty(this.getOrganName()) && TextUtils.isEmpty(this.getStationName())) {
            this.setStationName(this.getOrganName());
        }
        if (TextUtils.isEmpty(this.getDeviceName())) {
            this.setDeviceName(this.getDeviceCode());
        }
    }

    public void generateDefectNo() {
        if (null == this.getDefectNo() && !TextUtils.isEmpty(this.getDefectCode()) && this.getDefectCode().contains("-")) {
            String defectNoStr = this.getOrganNo().toString();
            String mid = this.getDefectCode().substring(2, 8);
            defectNoStr = defectNoStr + mid;
            String no = this.getDefectCode().substring(this.getDefectCode().lastIndexOf("-") + 1);
            no = String.format("%04d", Integer.parseInt(no));
            defectNoStr = defectNoStr + no;
            this.setDefectNo(Long.parseLong(defectNoStr));
        }
    }
}
